package com.lzy.cloud.payment.service.impl;

import com.github.pagehelper.PageInfo;
import com.lzy.cloud.payment.dtos.payment.PayWayDto;
import com.lzy.cloud.payment.entity.PayWay;
import com.lzy.cloud.payment.mapper.PayWayMapperExt;
import com.lzy.cloud.payment.service.PayWayService;
import com.lzy.cloud.payment.utils.CommonsUtil;
import com.lzy.framework.core.utils.DozerUtils;
import org.dozer.DozerBeanMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PayWayServiceImpl implements PayWayService {

	@Autowired
	private PayWayMapperExt payWayMapperExt;
	
	@Override
	public PayWayDto queryPayWayInfo(String name) {
		PayWayDto payWayDto = payWayMapperExt.queryPayWayInfo(name);
		return payWayDto;
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public PageInfo<PayWayDto> queryPayWayList() {
		List<PayWayDto> payWayDtoList = payWayMapperExt.queryPayWayList();
		PageInfo paygeInfo = new PageInfo(payWayDtoList);
		return paygeInfo;
	}

	@Override
	public boolean updatePayWayById(PayWayDto payWayDto) {
		int count = payWayMapperExt.updateByPrimaryKeySelective(DozerUtils.map(payWayDto,PayWay.class));
		return !CommonsUtil.isEmpty(count);
	}

	@Override
	public boolean addPayWayById(PayWayDto payWayDto) {
		int count = payWayMapperExt.insertSelective(DozerUtils.map(payWayDto,PayWay.class));
		return !CommonsUtil.isEmpty(count);
	}

	@Override
	public boolean deletePayWayById(Long id) {
		int count = payWayMapperExt.deleteByPrimaryKey(Integer.parseInt(id+""));
		return !CommonsUtil.isEmpty(count);
	}

	@Override
	public PayWayDto selectPayWayById(Long id) {
		return DozerUtils.map(payWayMapperExt.selectByPrimaryKey(Integer.parseInt(id + "")),PayWayDto.class);
	}

}
